#ifndef LINENUMBERAREA_H
#define LINENUMBERAREA_H

#include<QPlainTextEdit>
#include<QPaintEvent>

class CodeEditor : public QPlainTextEdit
  {
      Q_OBJECT

  public:
      CodeEditor(QWidget *parent = nullptr);

      void lineNumberAreaPaintEvent(QPaintEvent *event);
      int lineNumberAreaWidth();

  protected:
      void resizeEvent(QResizeEvent *event) override;

  private slots:
      void updateLineNumberAreaWidth(int newBlockCount);
      void highlightCurrentLine();
      void updateLineNumberArea(const QRect &, int);

  private:
      QWidget *lineNumberArea;
  };

class LineNumberArea : public QWidget
{
    Q_OBJECT
public:
    LineNumberArea(CodeEditor *editor) : QWidget(editor) {
        codeEditor = editor;
    }

    QSize sizeHint() const override {
        return QSize(codeEditor->lineNumberAreaWidth(), 0);
    }

protected:
    void paintEvent(QPaintEvent *event) override {
        codeEditor->lineNumberAreaPaintEvent(event);
    }

private:
    CodeEditor *codeEditor;
};

#endif // LINENUMBERAREA_H
